home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11870 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: FORTRAN and floats
  5. Date: 26 Mar 96 02:12:44 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.827806364@rscernix>
  8. References: <4j6on8$fif@mozo.cc.purdue.edu>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4j6on8$fif@mozo.cc.purdue.edu> rwa@bragg.bio.purdue.edu writes:
  13.  
  14. >I'm sure this is an easy one ... ;-)
  15.  
  16. Indeed :-)
  17.  
  18. >I write a "float" from C in Ultrix to a disk file as follows:
  19. >
  20. >    fwrite(&myFloat,sizeof(float),1,fOut);
  21. >
  22. >I get over to my Alpha Open VMS box and try and read it with FORTRAN and
  23. >get gibberish.  (Also can't do when writing from FORTRAN/VMS and reading in Ultrix/C).
  24. >
  25. >So FORTRAN/VMS likes a different format for floats than C/Ultrix.
  26.  
  27. Fortran on OpenVMS can be convinced to use the same representation
  28. for floats as the Ultrix system (IEEE 754), but this won't fix your
  29. problem.  You have to do additional tricks in the Fortran code to be
  30. able to read a binary file which wasn't produced by a Fortran program
  31. on the same platform.
  32.  
  33. >This is a portability issue that I'm sure there's a "clean" way to
  34. >solve it - does anyne have any ideas for me???
  35.  
  36. The clean and portable solution is to avoid binary files.  They're a pain
  37. in the ass even on the same platform, when they have to be used by
  38. programs written in different languages.  So, write your data in text
  39. format and both systems will understand it.
  40.  
  41. Dan
  42. --
  43. Dan Pop
  44. CERN, CN Division
  45. Email: danpop@mail.cern.ch 
  46. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  47.